﻿<cfsilent>
	<cfscript>
		
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		
		termId = event.getArg("TermID");
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		changeType = event.getArg("T");
		
		studentId = event.getArg("STU");
		
		docId = event.getArg("DOCID");
		
		currentTab = event.getArg("TabID", "labChooser");
		
		passArgs = structNew();
		structInsert( passArgs, "T", changeType );
		structInsert( passArgs, "TID", termId );
		structInsert( passArgs, "STU", studentId );
		structInsert( passArgs, "DOCID", docId );
		
		sql = "SELECT a.sct_name
				FROM t_stuchange_type a 
				WHERE a.sct_code = :changeType ";
				
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="changeType", value=changeType, cfsqltype = "cf_sql_char");

		rs_operObj = queryObj.execute( sql=sql ).getResult();
		
		event.setArg("pageTitle", "学生学籍管理 - 学籍异动 - " & rs_operObj.sct_name & "向导");
		
		/* 读取学生的已选课程 */
				
		sql = "SELECT 
				  a.cid, b.course_name, 
				  b.course_credit, c.turn, 
				  a.task_type, a.scc_id, 
				  a.st, a.retaking,a.choose_time, 
				  a.choose_prop, a.task_id, 
				  d.prop_name
				FROM t_student_course a  
				   INNER JOIN t_course b ON b.cid = a.cid 
				   INNER JOIN t_choose_turn c ON c.ct = a.ct 
				   INNER JOIN t_course_prop d ON d.prop_id = a.prop_id 
				WHERE 
					a.stu_id = :studentId 
					AND 
					a.term_id = :termId 
				ORDER BY a.task_type DESC, a.st, d.prop_name, b.course_name";
				
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype = "cf_sql_char");
		queryObj.addParam( name="studentId", value=studentId, cfsqltype = "cf_sql_varchar");

		rs_choosen = queryObj.execute( sql=sql ).getResult();
		
		/* 检查是否需要进行跨学期选课调整 */
		termChooseId = termId;
		
		sql = "SELECT a.term_id
				FROM t_term a  
				WHERE SUBSTR(a.term_prop, 5, 1) = '1'
				ORDER BY a.term_id";
				
		queryObj = new Query( datasource=application.dnsSlave );
		
		rs_chooseTerm = queryObj.execute( sql=sql ).getResult();
		if ( rs_chooseTerm.recordCount ) {
			if ( rs_chooseTerm["term_id"][1] neq termId ) {
				termChooseId = rs_chooseTerm["term_id"][1];

				/* 读取学生的已选课程 */
				
				sql = "SELECT 
				 		  a.cid, b.course_name, 
						  b.course_credit, c.turn, 
						  a.task_type, a.scc_id, 
						  a.st, a.retaking,a.choose_time, 
						  a.choose_prop, a.task_id, 
						  d.prop_name
						FROM t_student_course a  
						   INNER JOIN t_course b ON b.cid = a.cid 
						   INNER JOIN t_choose_turn c ON c.ct = a.ct 
						   INNER JOIN t_course_prop d ON d.prop_id = a.prop_id 
						WHERE 
							a.stu_id = :studentId 
							AND 
							a.term_id = :termId 
						ORDER BY a.task_type DESC, a.st, d.prop_name, b.course_name";
				
				queryObj = new Query( datasource=application.dnsSlave );
				queryObj.addParam( name="termId", value=termChooseId, cfsqltype = "cf_sql_char");
				queryObj.addParam( name="studentId", value=studentId, cfsqltype = "cf_sql_varchar");
		
				rs_choosenTerm = queryObj.execute( sql=sql ).getResult();
				
			}
		}

	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('studentStatusChange')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">学籍异动</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 card"></i>学籍异动向导 <cfoutput>#rs_operObj.sct_name#</cfoutput> 
				</h2>
			</div>
		</div>
	</div>
</div>

<!--- 加载导航菜单 --->
<!-- stepMenu-->
<cfoutput>#event.getArg("stepMenu")#</cfoutput>
<!--/stepMenu-->

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="findStudent">
				
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labChooser">class="active"</cfif> id="labChooser" tabTarget="Chooser">调整本学期选课</span>
						<cfif termChooseId neq termId>
							<span <cfif currentTab eq "labChooserNext">class="active"</cfif> id="labChooserNext" tabTarget="ChooserNext">后续学期选课调整</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
					
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
								
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					
					// -->
					//]]>
				</script>
				
				<div id="Chooser" class="tabContent">
					
					<div class="noticeBlock">
						<div class="operation">
							<cfset structInsert( passArgs, "StudentID", studentId, true ) />
							<cfset structInsert( passArgs, "TermID", termId, true ) />
							<cfset structInsert( passArgs, "TabID", "labChooser", true ) />
							<a class="uiButton" href="<cfoutput>#buildURL('statusChangeWizardModifyFeed', passArgs)#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">异动回执单</span></a>
							<a class="uiButton" href="<cfoutput>#buildURL('statusChangeWizardModifyRemoveAllCourseDO', passArgs)#</cfoutput>"><i class="mrs img btnClear"></i><span class="uiButtonText">清除课表</span></a>
							<a class="uiButton" href="<cfoutput>#buildURL('statusChangeWizardModifyPreRequiredCourseDO', passArgs)#</cfoutput>"><i class="mrs img btnAdd"></i><span class="uiButtonText">预置必修课</span></a>
						</div>
						<h3>当前运行学期选课情况列表</h3>
					</div>
					
					<cfif rs_choosen.recordCount>
						
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td>教学班</td>
									<td>任课教师</td>
									<td>学分</td>
									<td>开课类别</td>
									<td>修读方式</td>
									<td>性质</td>
									<td>重修</td>
									<td>上课时间</td>
									<td>上课地点</td>
									<td>选课时间</td>
									<td></td>
								</tr>
							</thead>
							<tbody>
								<cfset row = 0 />
                                <cfloop query="rs_choosen" >
									<cfset row++ />
									
									<!--- 读取教学任务教师和任务性质 --->
									<cfswitch expression="#rs_choosen.task_type#">
										<cfcase value="P">
                                        <cfset sql = "SELECT 
														b.tch_name, c.campus_name, a.task_week, 
														case when a.task_time is null then '-' else a.task_time end task_time, 
														case when a.task_place is null then '-' else a.task_place end task_place,
														a.task_prop, a.cidx 
														FROM t_task a 
														   INNER JOIN t_teacher b ON b.tch_id = a.tch_id 
														   INNER JOIN t_campus c ON c.campus_id = a.campus_id  
														WHERE a.tsk_id = :taskId"/>
										</cfcase>
										<cfcase value="C">
                                        <cfset sql = "SELECT 
														b.tch_name, c.campus_name, a.task_week, 
														case when a.task_time is null then '-' else a.task_time end task_time, 
														case when a.task_place is null then '-' else a.task_place end task_place,
														a.task_prop, a.cidx 
														FROM t_common_task a 
														   INNER JOIN t_teacher b ON b.tch_id = a.tch_id 
														   INNER JOIN t_campus c ON c.campus_id = a.campus_id  
														WHERE a.tsk_id = :taskId"/>
										</cfcase>
										<cfcase value="R">
                                        <cfset sql = "SELECT 
														b.tch_name, c.campus_name, a.task_week, 
														case when a.task_time is null then '-' else a.task_time end task_time, 
														case when a.task_place is null then '-' else a.task_place end task_place,
														a.task_prop, a.cidx 
														FROM t_reopen_task a 
														   INNER JOIN t_teacher b ON b.tch_id = a.tch_id 
														   INNER JOIN t_campus c ON c.campus_id = a.campus_id  
														WHERE a.tsk_id = :taskId"/>
										</cfcase>
										<cfcase value="T">
                                        <cfset sql = "SELECT 
														b.tch_name, c.campus_name, a.task_week, 
														case when a.task_time is null then '-' else a.task_time end task_time, 
														case when a.task_place is null then '-' else a.task_place end task_place,
														a.task_prop, a.cidx 
														FROM t_sport_task a 
														   INNER JOIN t_teacher b ON b.tch_id = a.tch_id 
														   INNER JOIN t_campus c ON c.campus_id = a.campus_id  
														WHERE a.tsk_id = :taskId"/>
										</cfcase>
									</cfswitch>
                                    <cfset queryObj = new Query( datasource=application.dnsSlave )/>
                                    <cfset queryObj.addParam( name="taskId", value=rs_choosen.task_id, cfsqltype="cf_sql_varchar" )/>
                                    <cfset rs_task = queryObj.execute( sql=sql ).getResult()/>
									<cfif rs_task.recordCount>
										<!--- 如果教学任务有效 --->
										<cfset structInsert( passArgs, "ChooseID", rs_choosen.scc_id, true ) />
										<cfset structInsert( passArgs, "TaskType", rs_choosen.task_type, true ) />
										<cfset structInsert( passArgs, "TaskID", rs_choosen.task_id, true ) />
										<tr class="editRows <cfif rs_choosen.st eq "R">noticeRow1</cfif> <cfif rs_choosen.st eq "F">noticeRow2</cfif>">
											<td><span class="index"><cfoutput>#row#</cfoutput></span></td>
											<td><cfoutput>#rs_choosen.course_name#</cfoutput></td>
											<td><cfoutput>#rs_task["tch_name"][1]#</cfoutput></td>
											<td><span class="numeric"><cfoutput>#numberFormat(rs_choosen.course_credit, '_.__')#</cfoutput></span></td>
											<td><cfoutput>#dictAdvice.getTaskType( rs_choosen.task_type )#</cfoutput></td>
											<td><cfoutput>#dictAdvice.getStudyType( rs_choosen.st )#</cfoutput></td>
											<td><cfoutput>#rs_choosen.prop_name#</cfoutput></td>
											<td><cfif rs_choosen.retaking eq "1">是<cfelse>否</cfif></td>
											<td><cfoutput>#replace(mathAdvice.convertTaskTime(rs_task["task_time"][1]), ",", "<br/>", "all")#</cfoutput></td>
											<td><cfoutput>#replace(rs_task["task_place"][1], ",", "<br/>", "all")#</cfoutput></td>
											<td><span class="numeric"><cfoutput>#datetimeAdvice.formatDatetimeString(rs_choosen.choose_time, 'YYYY/MM/DD')#</cfoutput></span></td>
											<td><a title="撤销课程" class="stat delete" href="<cfoutput>#buildURL('statusChangeWizardModifyRemoveCourseDO', passArgs)#</cfoutput>"></a></td>
										</tr>
										<!--- javascript:removeTask(chooserId, courseId, stuId, termId, taskType, taskId); --->
										<cfelse>
										<!--- 如果教学任务无效 则直接删除错误的选课记录 --->
									</cfif>
								</cfloop>
								<!--- 清除多余参数 --->
								<cfset structDelete( passArgs, "ChooseID", false ) />
								<cfset structDelete( passArgs, "TaskType", false ) />
								<cfset structDelete( passArgs, "TaskID", false ) />
							</tbody>
						</table>
						<cfelse>
						<div class="systemNotice">
							<h3>学生没有选课</h3>
						</div>
					</cfif>
					
				</div>

				<cfif termChooseId neq termId>
				
					<div id="ChooserNext" class="tabContent">
						
						<div class="noticeBlock">
							<div class="operation">
								<cfset structInsert( passArgs, "StudentID", studentId, true ) />
								<cfset structInsert( passArgs, "TermID", termChooseId, true ) />
								<cfset structInsert( passArgs, "TabID", "labChooserNext", true ) />
								<a class="uiButton" href="<cfoutput>#buildURL('statusChangeWizardModifyFeed', passArgs)#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">异动回执单</span></a>
								<a class="uiButton" href="<cfoutput>#buildURL('statusChangeWizardModifyRemoveAllCourseDO', passArgs)#</cfoutput>"><i class="mrs img btnClear"></i><span class="uiButtonText">清除课表</span></a>
								<a class="uiButton" href="<cfoutput>#buildURL('statusChangeWizardModifyPreRequiredCourseDO', passArgs)#</cfoutput>"><i class="mrs img btnAdd"></i><span class="uiButtonText">预置必修课</span></a>
							</div>
							<h3>后续学期选课情况列表</h3>
						</div>
						
						<cfif rs_choosenTerm.recordCount>
							<table class="UIEditable">
								<thead>
									<tr>
										<td width="18"></td>
										<td>教学班</td>
										<td>任课教师</td>
										<td>学分</td>
										<td>开课类别</td>
										<td>修读方式</td>
										<td>性质</td>
										<td>重修</td>
										<td>上课时间</td>
										<td>上课地点</td>
										<td>选课时间</td>
										<td></td>
									</tr>
								</thead>
								<tbody>
									<cfset row = 0 />
                                    <cfloop query="rs_choosenTerm" >
										<cfset row++ />
										
										<!--- 读取教学任务教师和任务性质 --->
										<cfswitch expression="#rs_choosenTerm.task_type#">
											<cfcase value="P">
											<cfset sql = "SELECT 
															b.tch_name, c.campus_name, a.task_week, 
															case when a.task_time is null then '-' else a.task_time end task_time, 
															case when a.task_place is null then '-' else a.task_place end task_place,
															a.task_prop, a.cidx 
															FROM t_task a 
															   INNER JOIN t_teacher b ON b.tch_id = a.tch_id 
															   INNER JOIN t_campus c ON c.campus_id = a.campus_id  
															WHERE a.tsk_id = :taskId"/>
											</cfcase>
											<cfcase value="C">
											<cfset sql = "SELECT 
															b.tch_name, c.campus_name, a.task_week, 
															case when a.task_time is null then '-' else a.task_time end task_time, 
															case when a.task_place is null then '-' else a.task_place end task_place,
															a.task_prop, a.cidx 
															FROM t_common_task a 
															   INNER JOIN t_teacher b ON b.tch_id = a.tch_id 
															   INNER JOIN t_campus c ON c.campus_id = a.campus_id  
															WHERE a.tsk_id = :taskId"/>
											</cfcase>
											<cfcase value="R">
											<cfset sql = "SELECT 
															b.tch_name, c.campus_name, a.task_week, 
															case when a.task_time is null then '-' else a.task_time end task_time, 
															case when a.task_place is null then '-' else a.task_place end task_place,
															a.task_prop, a.cidx 
															FROM t_reopen_task a 
															   INNER JOIN t_teacher b ON b.tch_id = a.tch_id 
															   INNER JOIN t_campus c ON c.campus_id = a.campus_id  
															WHERE a.tsk_id = :taskId"/>
											</cfcase>
											<cfcase value="T">
											<cfset sql = "SELECT 
															b.tch_name, c.campus_name, a.task_week, 
															case when a.task_time is null then '-' else a.task_time end task_time, 
															case when a.task_place is null then '-' else a.task_place end task_place,
															a.task_prop, a.cidx 
															FROM t_sport_task a 
															   INNER JOIN t_teacher b ON b.tch_id = a.tch_id 
															   INNER JOIN t_campus c ON c.campus_id = a.campus_id  
															WHERE a.tsk_id = :taskId"/>
											</cfcase>
										</cfswitch>
										<cfset queryObj = new Query( datasource=application.dnsSlave )/>
										<cfset queryObj.addParam( name="taskId", value=rs_choosenTerm.task_id, cfsqltype="cf_sql_varchar" )/>
										<cfset rs_taskTerm = queryObj.execute( sql=sql ).getResult()/>
										<cfif rs_taskTerm.recordCount>
											<!--- 如果教学任务有效 --->
											<cfset task = taskArray[1] />
											<cfset structInsert( passArgs, "ChooseID", rs_choosenTerm.scc_id, true ) />
											<cfset structInsert( passArgs, "TaskType", rs_choosenTerm.task_type, true ) />
											<cfset structInsert( passArgs, "TaskID", rs_choosenTerm.task_id, true ) />
											<tr class="editRows <cfif rs_choosenTerm.st eq "R">noticeRow1</cfif> <cfif rs_choosenTerm.st eq "F">noticeRow2</cfif>">
												<td><span class="index"><cfoutput>#row#</cfoutput></span></td>
												<td><cfoutput>#rs_choosenTerm.course_name#</cfoutput></td>
												<td><cfoutput>#rs_taskTerm["tch_name"][1]#</cfoutput></td>
												<td><span class="numeric"><cfoutput>#numberFormat(rs_choosenTerm.course_credit, '_.__')#</cfoutput></span></td>
												<td><cfoutput>#dictAdvice.getTaskType( rs_choosenTerm.task_type )#</cfoutput></td>
												<td><cfoutput>#dictAdvice.getStudyType( rs_choosenTerm.st )#</cfoutput></td>
												<td><cfoutput>#rs_choosenTerm.prop_name#</cfoutput></td>
												<td><cfif rs_choosenTerm.retaking eq "1">是<cfelse>否</cfif></td>
												<td><cfoutput>#replace(mathAdvice.convertTaskTime(rs_taskTerm["task_time"][1]), ",", "<br/>", "all")#</cfoutput></td>
												<td><cfoutput>#replace(rs_taskTerm["task_place"][1], ",", "<br/>", "all")#</cfoutput></td>
												<td><span class="numeric"><cfoutput>#datetimeAdvice.formatDatetimeString(rs_choosenTerm.choose_time, 'YYYY/MM/DD')#</cfoutput></span></td>
												<td><a title="撤销课程" class="stat delete" href="<cfoutput>#buildURL('statusChangeWizardModifyRemoveCourseDO', passArgs)#</cfoutput>"></a></td>
											</tr>
											<!--- javascript:removeTask(chooserId, courseId, stuId, termId, taskType, taskId); --->
											<cfelse>
											<!--- 如果教学任务无效 则直接删除错误的选课记录 --->
										</cfif>
									</cfloop>
									<!--- 清除多余参数 --->
									<cfset structDelete( passArgs, "ChooseID", false ) />
									<cfset structDelete( passArgs, "TaskType", false ) />
									<cfset structDelete( passArgs, "TaskID", false ) />
								</tbody>
							</table>
							<cfelse>
							<div class="systemNotice">
								<h3>学生没有选课</h3>
							</div>
						</cfif>
						
					</div>
				
				</cfif>

				
			</div>
		</li>
	</ul>
</div>